package com.marsoft.test.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marsoft.test.entity.EffectContEntity;
import com.marsoft.test.entity.YaPinManageEntity;
import com.marsoft.test.mapper.EffectContMapper;
import com.marsoft.test.service.EffectContService;
import com.marsoft.test.utils.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EffectContServiceImpl implements EffectContService {
    @Autowired
    private EffectContMapper tEffectContMapper;
    @Override
    public List<EffectContEntity> getEffectCont(Integer id) {

        List<EffectContEntity> effectCont = tEffectContMapper.getEffectCont(id);
        return effectCont;
    }

    @Override
    public String getName(Integer id) {
        String name=tEffectContMapper.getName(id);
        return name;
    }

    /**
      *@author:he
      *@Date:2021/5/14 10:25
      *@Description:有效的一般合同分页操作
      */
    @Override
    public List<EffectContEntity> getEffectContByState(Integer id, Integer guarantyContractStatus, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<EffectContEntity> effectCont = tEffectContMapper.getEffectContByState(id,guarantyContractStatus);
        PageInfo pageInfo = new PageInfo(effectCont);
        return pageInfo.getList();
    }

    @Override
    public ResultMap addYP(YaPinManageEntity tYaPinManageEntity) {
        ResultMap resultMap=new ResultMap();
        /**
          *@author:he
          *@Date:2021/5/20 15:36
          *@Description:保险单号不能为空
          */
        Integer insuranceNo=tYaPinManageEntity.getInsuranceNo();
        if(insuranceNo==null){
            return resultMap.error().put("保险单号不能为空",tEffectContMapper.addYP(tYaPinManageEntity));
        }

        return resultMap.put("增加押品信息成功",tEffectContMapper.addYP(tYaPinManageEntity));
    }

    /**
      *@author:he
      *@Date:2021/5/20 17:37
      *@Description:抵押物详情修改
      */
    @Override
    public ResultMap updateYP(YaPinManageEntity tYaPinManageEntity){
        ResultMap resultMap=new ResultMap();
        return resultMap.put("增加押品信息成功",tEffectContMapper.updateYP(tYaPinManageEntity));
    }
    /**
      *@author:he
      *@Date:2021/5/21 10:12
      *@Description:删除抵押物信息
      */
    @Override
    public ResultMap deleteYP(YaPinManageEntity tYaPinManageEntity) {
        ResultMap resultMap=new ResultMap();
        return resultMap.put("删除押品信息成功",tEffectContMapper.deleteYP(tYaPinManageEntity));
    }
}
